<template>
  <div class="header">
    <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
      <span class="iconfont back-icon">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      <router-link to="/">
        <div class="header-back">
          <span class="iconfont">&#xe624;</span>
        </div>
      </router-link>
      {{sightName}}</div>
  </div>
</template>
<script>
export default {
  name: "detailHeader",
  data() {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  props: {
    sightName: String
  },
  methods: {
    handleScroll () {
      let scrollTop = document.body.scrollTop
      console.log(scrollTop)
      if(scrollTop > 60) {
        let opacity = scrollTop / 140
        opacity > 1 ? 1 : scrollTop
        this.opacityStyle = { opacity }
        this.showAbs = false
      }else{
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
};
</script>
<style lang="scss" scoped>
@import "~styles/varibles.scss";

.header-abs {
  position: absolute;
  left: 0.2rem;
  top: 0.2rem;
  width: 0.8rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.8);
  text-align: center;
  .back-icon {
    color: #fff;
  }
}
.header-fixed {
  height: 0.86rem;
  z-index: 98;
  line-height: 0.86rem;
  color: #fff;
  overflow: hidden;
  text-align: center;
  background-color: $baseColor;
  font-size: 0.32rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  .header-back {
    width: 0.64rem;
    text-align: center;
    color: #fff;
    font-size: 0.4rem;
    position: absolute;
    top: 0;
    left: 0;
  }
}
</style>


